package com.groupfifteen.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.groupfifteen.entity.SysDictTypeEntity;
import com.groupfifteen.entity.SysUserEntity;
import com.groupfifteen.service.SysDictTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.Map;


/**
 * 字典类型表
 *
 */
@Slf4j
@RestController
@RequestMapping("backend/dictType")
public class SysDictTypeController  {

    @Autowired
    private SysDictTypeService sysDictTypeService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public IPage list(@RequestBody Map<String, Object> params) {
        IPage<SysDictTypeEntity> page = sysDictTypeService.queryPage(params);
        return page;
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{dictId}")
    public SysDictTypeEntity info(@PathVariable("dictId") Long dictId) {
        SysDictTypeEntity sysDictType = sysDictTypeService.getById(dictId);
        return sysDictType;
    }

    @PostMapping("adddicttype")
    public String AddDictType(@RequestBody SysDictTypeEntity sysDictTypeEntity) {
        Integer result = sysDictTypeService.AddDictType(sysDictTypeEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }




    @DeleteMapping("/deletedicttype/{dictId}")
    public String deleteDictType(@PathVariable("dictId") Integer dictId) {
        Integer result = sysDictTypeService.deleteDictType(dictId);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }
    @GetMapping("/getdicttype/{dictId}")
    public SysDictTypeEntity GetDictType(@PathVariable("dictId") Integer dictId) {
        SysDictTypeEntity result = sysDictTypeService.GetDictType(dictId);
        if (result != null) {
            return result;
        } else {
            return null;
        }
    }

    @PutMapping("/updatedicttype/{dictId}")
    public String UpdateDictType(@PathVariable("dictId")long dictId,@RequestBody SysDictTypeEntity sysDictTypeEntity) {
        sysDictTypeEntity.setDictId(dictId);
        Integer result = sysDictTypeService.UpdateDictType(sysDictTypeEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }

}
